<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.8.0">
    

    

    



    <meta charset="utf-8">
    
    
    
    
    <title>mpvue-使用flyio发起request请求 | lafen | lafen&#39;s personal blog</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    
    <meta name="theme-color" content="#3F51B5">
    
    
    <meta name="keywords" content="mpvue">
    <meta name="description" content="背景由于小程序中不能使用axios发起请求，平时在做小程序的时候也只能自己封装一下wx.request来用，但之前看到flyio竟然支持小程序，而且用法还跟axios类似，赶紧去使用一下 简介1微信小程序的 javascript 运行环境和浏览器不同，页面的脚本逻辑是在JsCore中运行，JsCore是一个没有窗口对象的环境，所以不能在脚本中使用window，也无法在脚本中操作组件，JsCore中">
<meta name="keywords" content="mpvue">
<meta property="og:type" content="article">
<meta property="og:title" content="mpvue-使用flyio发起request请求">
<meta property="og:url" content="https://lafen.gitee.io/2019/08/30/mpvue-使用flyio发起request请求/mpvue-使用flyio发起request请求/index.html">
<meta property="og:site_name" content="lafen">
<meta property="og:description" content="背景由于小程序中不能使用axios发起请求，平时在做小程序的时候也只能自己封装一下wx.request来用，但之前看到flyio竟然支持小程序，而且用法还跟axios类似，赶紧去使用一下 简介1微信小程序的 javascript 运行环境和浏览器不同，页面的脚本逻辑是在JsCore中运行，JsCore是一个没有窗口对象的环境，所以不能在脚本中使用window，也无法在脚本中操作组件，JsCore中">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2019-09-17T05:44:37.921Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="mpvue-使用flyio发起request请求">
<meta name="twitter:description" content="背景由于小程序中不能使用axios发起请求，平时在做小程序的时候也只能自己封装一下wx.request来用，但之前看到flyio竟然支持小程序，而且用法还跟axios类似，赶紧去使用一下 简介1微信小程序的 javascript 运行环境和浏览器不同，页面的脚本逻辑是在JsCore中运行，JsCore是一个没有窗口对象的环境，所以不能在脚本中使用window，也无法在脚本中操作组件，JsCore中">
    
        <link rel="alternate" type="application/atom+xml" title="lafen" href="/atom.xml">
    
    <link rel="shortcut icon" href="/img/favicon.ico">
    <link rel="stylesheet" href="//unpkg.com/hexo-theme-material-indigo@latest/css/style.css">
    <script>window.lazyScripts=[]</script>

    <!-- custom head -->
    

</head>

<body>
    <div id="loading" class="active"></div>

    <aside id="menu" class="hide">
  <div class="inner flex-row-vertical">
    <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menu-off">
        <i class="icon icon-lg icon-close"></i>
    </a>
    <div class="brand-wrap" style="background-image:url(/img/brand.jpg)">
      <div class="brand">
        <a href="/" class="avatar waves-effect waves-circle waves-light">
          <img src="/img/avatar.jpg">
        </a>
        <hgroup class="introduce">
          <h5 class="nickname">lafen</h5>
          <a href="mailto:1031822863@qq.com" title="1031822863@qq.com" class="mail">1031822863@qq.com</a>
        </hgroup>
      </div>
    </div>
    <div class="scroll-wrap flex-col">
      <ul class="nav">
        
            <li class="waves-block waves-effect">
              <a href="/">
                <i class="icon icon-lg icon-home"></i>
                home
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/archives">
                <i class="icon icon-lg icon-archives"></i>
                Archives
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/tags">
                <i class="icon icon-lg icon-tags"></i>
                Tags
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/categories">
                <i class="icon icon-lg icon-th-list"></i>
                Categories
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://github.com/zhongxiaotian" target="_blank">
                <i class="icon icon-lg icon-github"></i>
                Github
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="http://www.weibo.com/" target="_blank">
                <i class="icon icon-lg icon-weibo"></i>
                Weibo
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://gitee.com/lafen" target="_blank">
                <i class="icon icon-lg icon-link"></i>
                Gitee
              </a>
            </li>
        
      </ul>
    </div>
  </div>
</aside>

    <main id="main">
        <header class="top-header" id="header">
    <div class="flex-row">
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light on" id="menu-toggle">
          <i class="icon icon-lg icon-navicon"></i>
        </a>
        <div class="flex-col header-title ellipsis">mpvue-使用flyio发起request请求</div>
        
        <div class="search-wrap" id="search-wrap">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="back">
                <i class="icon icon-lg icon-chevron-left"></i>
            </a>
            <input type="text" id="key" class="search-input" autocomplete="off" placeholder="输入感兴趣的关键字">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="search">
                <i class="icon icon-lg icon-search"></i>
            </a>
        </div>
        
        
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menuShare">
            <i class="icon icon-lg icon-share-alt"></i>
        </a>
        
    </div>
</header>
<header class="content-header post-header">

    <div class="container fade-scale">
        <h1 class="title">mpvue-使用flyio发起request请求</h1>
        <h5 class="subtitle">
            
                <time datetime="2019-08-30T02:14:22.000Z" itemprop="datePublished" class="page-time">
  2019-08-30
</time>


	<ul class="article-category-list"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/mpvue/">mpvue</a></li></ul>

            
        </h5>
    </div>

    


</header>


<div class="container body-wrap">
    
    <aside class="post-widget">
        <nav class="post-toc-wrap post-toc-shrink" id="post-toc">
            <h4>TOC</h4>
            <ol class="post-toc"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#背景"><span class="post-toc-number">1.</span> <span class="post-toc-text">背景</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#简介"><span class="post-toc-number">2.</span> <span class="post-toc-text">简介</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#下载"><span class="post-toc-number">3.</span> <span class="post-toc-text">下载</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#使用封装"><span class="post-toc-number">4.</span> <span class="post-toc-text">使用封装</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#创建实例"><span class="post-toc-number">4.1.</span> <span class="post-toc-text">创建实例</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#基准路径"><span class="post-toc-number">4.2.</span> <span class="post-toc-text">基准路径</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#导出实例"><span class="post-toc-number">4.3.</span> <span class="post-toc-text">导出实例</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#发起请求"><span class="post-toc-number">4.4.</span> <span class="post-toc-text">发起请求</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#请求拦截"><span class="post-toc-number">4.5.</span> <span class="post-toc-text">请求拦截</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#响应拦截"><span class="post-toc-number">4.6.</span> <span class="post-toc-text">响应拦截</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#token失效问题"><span class="post-toc-number">4.7.</span> <span class="post-toc-text">token失效问题</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#token失效处理"><span class="post-toc-number">4.8.</span> <span class="post-toc-text">token失效处理</span></a></li></ol></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#总结"><span class="post-toc-number">5.</span> <span class="post-toc-text">总结</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#代码"><span class="post-toc-number">6.</span> <span class="post-toc-text">代码</span></a></li></ol>
        </nav>
    </aside>


<article id="post-mpvue-使用flyio发起request请求/mpvue-使用flyio发起request请求" class="post-article article-type-post fade" itemprop="blogPost">

    <div class="post-card">
        <h1 class="post-card-title">mpvue-使用flyio发起request请求</h1>
        <div class="post-meta">
            <time class="post-time" title="2019-08-30 10:14:22" datetime="2019-08-30T02:14:22.000Z" itemprop="datePublished">2019-08-30</time>

            
	<ul class="article-category-list"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/mpvue/">mpvue</a></li></ul>



            
<span id="busuanzi_container_page_pv" title="文章总阅读量" style="display:none">
    <i class="icon icon-eye icon-pr"></i><span id="busuanzi_value_page_pv"></span>
</span>


        </div>
        <div class="post-content" id="post-content" itemprop="postContent">
            <h3 id="背景"><a href="#背景" class="headerlink" title="背景"></a>背景</h3><p>由于小程序中不能使用<code>axios</code>发起请求，平时在做小程序的时候也只能自己封装一下<code>wx.request</code>来用，但之前看到<code>flyio</code>竟然支持小程序，而且用法还跟<code>axios</code>类似，赶紧去使用一下</p>
<h3 id="简介"><a href="#简介" class="headerlink" title="简介"></a>简介</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">微信小程序的 javascript 运行环境和浏览器不同，页面的脚本逻辑是在JsCore中运行，JsCore是一个没有窗口对象的环境，所以不能在脚本中使用<span class="built_in">window</span>，也无法在脚本中操作组件，JsCore中也没有 XmlhttpRequest对象，所以jquery 、zepto、axios这些在小程序中都不能用，而此时，正是 fly 大显身手的时候。</span><br></pre></td></tr></table></figure>
<p>以上就是<a href="https://wendux.github.io/dist/#/doc/flyio/wx" target="_blank" rel="noopener">flyio官网</a>的介绍</p>
<h3 id="下载"><a href="#下载" class="headerlink" title="下载"></a>下载</h3><p>我使用的<code>mpvue</code>，通过<code>npm</code>来管理依赖</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install flyio --save</span><br></pre></td></tr></table></figure>
<h3 id="使用封装"><a href="#使用封装" class="headerlink" title="使用封装"></a>使用封装</h3><p>在项目中引入<code>flyio</code>并创建<code>flyio</code>实例，首先在<code>utils</code>文件夹下新建<code>fly.js</code>文件</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">├── src</span><br><span class="line">|   ├── api</span><br><span class="line">|   ├── ├── api.js</span><br><span class="line">|   ├── utils</span><br><span class="line">|   ├── ├── fly.js</span><br></pre></td></tr></table></figure>
<h4 id="创建实例"><a href="#创建实例" class="headerlink" title="创建实例"></a>创建实例</h4><p><code>fly.js</code>中实例如下</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// fly.js</span></span><br><span class="line"><span class="keyword">var</span> Fly = <span class="built_in">require</span>(<span class="string">'flyio/dist/npm/wx'</span>) <span class="comment">// 引入</span></span><br><span class="line"><span class="keyword">var</span> fly = <span class="keyword">new</span> Fly() <span class="comment">// 创建fly实例</span></span><br></pre></td></tr></table></figure>
<h4 id="基准路径"><a href="#基准路径" class="headerlink" title="基准路径"></a>基准路径</h4><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">fly.config.baseURL = <span class="string">'https://example/api'</span></span><br></pre></td></tr></table></figure>
<h4 id="导出实例"><a href="#导出实例" class="headerlink" title="导出实例"></a>导出实例</h4><p>默认导出实例<code>fly</code></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> fly</span><br></pre></td></tr></table></figure>
<h4 id="发起请求"><a href="#发起请求" class="headerlink" title="发起请求"></a>发起请求</h4><p>将<code>fly</code>实例导出之后即可像使用<code>axios</code>那样使用啦，在<code>api</code>文件夹下新建<code>api.js</code>文件，导入实例<code>fly</code>后使用</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// api.js</span></span><br><span class="line"><span class="keyword">import</span> fly <span class="keyword">from</span> <span class="string">'@/utils/fly'</span></span><br><span class="line"><span class="comment">// 获取banner数据</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">const</span> getSwiperList = <span class="function"><span class="params">data</span> =&gt;</span> fly.post(<span class="string">'/swiper'</span>, data)</span><br></pre></td></tr></table></figure>
<p>如果想要发起<code>get</code>请求，只需将<code>post</code>改为<code>get</code>即可。</p>
<p>那么在页面中就可以这样来使用了</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// index.vue</span></span><br><span class="line">&lt;script&gt;</span><br><span class="line"><span class="keyword">import</span> &#123; getSwiperList &#125; <span class="keyword">from</span> <span class="string">'@/api/api'</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> &#123;</span><br><span class="line">  methods: &#123;</span><br><span class="line">    fetchSwiperList () &#123;</span><br><span class="line">      getSwiperList(&#123; <span class="string">"cmd"</span>:<span class="string">"getPost"</span> &#125;).then(<span class="function">(<span class="params">res</span>) =&gt;</span> &#123;</span><br><span class="line">        <span class="comment">// res.result</span></span><br><span class="line">        <span class="keyword">this</span>.list = res.result</span><br><span class="line">      &#125;).catch(<span class="function">(<span class="params">err</span>) =&gt;</span> &#123;</span><br><span class="line">        <span class="built_in">console</span>.log(err)</span><br><span class="line">      &#125;)</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line">&lt;<span class="regexp">/script&gt;</span></span><br></pre></td></tr></table></figure>
<p>炒鸡方便呀，完全不用写啥<code>wx.request</code>，然后写一堆参数之类的，完全跟<code>axios</code>书写一样的体验。</p>
<p>但是仅仅是这样怎么能满足呢，还得加上拦截器，接下来回到<code>utils/fly.js</code>中，给<code>fly</code>添加上拦截器</p>
<h4 id="请求拦截"><a href="#请求拦截" class="headerlink" title="请求拦截"></a>请求拦截</h4><p>在请求头<code>header</code>中带上后端校验需要的参数，比如<code>token</code>或<code>user_id</code>，我方直接在参数中带上，故直接给<code>body</code>赋值</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// fly.js</span></span><br><span class="line">fly.interceptors.request.use(<span class="function">(<span class="params">config, promise</span>) =&gt;</span> &#123;</span><br><span class="line">  config.body[<span class="string">'token'</span>] = wx.getStorageSync(<span class="string">'Token'</span>)</span><br><span class="line">  config.body[<span class="string">'user_id'</span>] = wx.getStorageSync(<span class="string">'UserId'</span>)</span><br><span class="line">  <span class="comment">// config.headers['token'] = wx.getStorageSync('Token') // 请求头中带token</span></span><br><span class="line">  <span class="keyword">return</span> config</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
<p>因为是在小程序中，所以可以直接使用微信的<code>api</code>从缓存中获取到<code>token</code>，甚至，还可以加上<code>loading</code>的状态提示</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">fly.interceptors.request.use(<span class="function">(<span class="params">config, promise</span>) =&gt;</span> &#123;</span><br><span class="line">  <span class="comment">// 页面loading提示</span></span><br><span class="line">  wx.showLoading(&#123; <span class="attr">title</span>: <span class="string">'Loading...'</span> &#125;)</span><br><span class="line">  <span class="comment">// 状态栏loading提示</span></span><br><span class="line">  wx.showNavigationBarLoading()</span><br><span class="line">  </span><br><span class="line">  ...</span><br><span class="line">  <span class="keyword">return</span> config</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
<p><strong>注意：</strong> 记得要在请求完毕之后关闭<code>loading</code>，响应拦截中处理即可</p>
<h4 id="响应拦截"><a href="#响应拦截" class="headerlink" title="响应拦截"></a>响应拦截</h4><p>关闭<code>loading</code>提示</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// fly.js</span></span><br><span class="line">fly.interceptors.response.use(<span class="function"><span class="keyword">function</span> (<span class="params">res</span>)</span>&#123;</span><br><span class="line">  <span class="comment">// 关闭页面loading</span></span><br><span class="line">  wx.hideLoading()</span><br><span class="line">  <span class="comment">// 关闭状态栏loading</span></span><br><span class="line">  wx.hideNavigationBarLoading()</span><br><span class="line">  </span><br><span class="line">  ...</span><br><span class="line">  <span class="keyword">return</span> res.data</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
<p>可根据项目的实际情况，在拦截器中做相应的逻辑</p>
<h4 id="token失效问题"><a href="#token失效问题" class="headerlink" title="token失效问题"></a>token失效问题</h4><p>在请求拦截中，我们给每个请求都带上了<code>token</code>给后端，但是我们并不知道<code>token</code>到底什么时候失效，只能后端校验<code>token</code>之后返回给我们。</p>
<ol>
<li><p>如果<code>token</code>没失效，则后端之后返回了该次请求的结果。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">request--&gt;（携带token）--&gt;服务器判断token--&gt;返回json数据</span><br></pre></td></tr></table></figure>
</li>
<li><p>如果<code>token</code>失效了，则应当先发起登录的请求，拿到最新的<code>token</code>，然后再重新发起该次请求拿到数据。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">request--&gt;（携带token）--&gt;服务器判断token--&gt;返回token失效--&gt;重新发起登录--&gt;服务器返回最新token--&gt;（携带最新token）重新发起该次请求</span><br></pre></td></tr></table></figure>
</li>
</ol>
<p>当然<code>fly</code>也考虑到这些问题，故也支持在拦截器中执行异步任务，并提供<code>lock</code>和<code>unlock</code>这两个<code>api</code>，详细可见文档<a href="https://wendux.github.io/dist/#/doc/flyio/interceptor" target="_blank" rel="noopener">拦截器</a>部分</p>
<h4 id="token失效处理"><a href="#token失效处理" class="headerlink" title="token失效处理"></a>token失效处理</h4><p>接下来则对<code>token</code>失效问题进行处理，在响应拦截中判断</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 响应拦截</span></span><br><span class="line">fly.interceptors.response.use(<span class="function"><span class="keyword">function</span> (<span class="params">res</span>)</span>&#123;</span><br><span class="line">  ...</span><br><span class="line">  <span class="comment">// errcode === -1  =&gt;token过期 =&gt; 重新登录处理</span></span><br><span class="line">  <span class="keyword">if</span>(res.data.errcode === <span class="number">-1</span>) &#123;</span><br><span class="line">    <span class="keyword">this</span>.lock() <span class="comment">// 锁定当前实例，后续请求会在拦截器外排队</span></span><br><span class="line">    <span class="keyword">return</span> wxLogin(&#123;<span class="string">'reLogin'</span>: <span class="literal">true</span> &#125;).then(<span class="function"><span class="params">r</span> =&gt;</span> &#123;</span><br><span class="line">      <span class="keyword">this</span>.unlock() <span class="comment">// 解锁，因小程序中无finally，只能在此解锁</span></span><br><span class="line">      <span class="keyword">return</span> fly.request(res.request) <span class="comment">// 只有最终返回request对象，原来的请求才会继续</span></span><br><span class="line">    &#125;).catch(<span class="function"><span class="params">err</span> =&gt;</span> <span class="keyword">this</span>.unlock())</span><br><span class="line">  &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">    <span class="comment">// 返回</span></span><br><span class="line">    <span class="keyword">return</span> res.data</span><br><span class="line">  &#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
<p>例如后端定义<code>errcode===-1</code>则表示<code>token</code>过期，则在响应拦截器中对其处理</p>
<ol>
<li><p><code>this.lock()</code>是<code>fly</code>提供的<code>api</code>，表示将该<code>fly</code>实例锁定，需要处理完毕后使用<code>this.unlock()</code>进行解锁。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">注意： <span class="keyword">this</span>指向当前拦截器对象，相当于fly.interceptors.response.lock()</span><br><span class="line">如果拦截器使用箭头函数，使用<span class="keyword">this</span>则会导致指向有问题，此时需要使用fly.interceptors.response.lock()来锁定</span><br></pre></td></tr></table></figure>
</li>
</ol>
<ol start="2">
<li><p><code>return</code>调用<code>wxLogin</code>登录接口的处理结果。请求成功后<code>this.unlock()</code>解锁（<code>catch</code>块中也解锁），并返回<code>request</code>对象，即原来的请求<code>request</code>对象</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">注意： reLogin:<span class="literal">true</span>表示重新登录，<span class="literal">false</span>(默认)则正常调用登录，原因见下文</span><br><span class="line">因为小程序中不支持<span class="keyword">finally</span>块，故只能在then和<span class="keyword">catch</span>中进行解锁<span class="keyword">this</span>.unlock()</span><br></pre></td></tr></table></figure>
</li>
</ol>
<p>接下来看看<code>wxLogin</code>中的代码</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// fly.js</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">const</span> wxLogin = <span class="function">(<span class="params">&#123; cmd = <span class="string">'userLogin'</span>, reLogin = <span class="literal">false</span> &#125; = &#123; cmd: <span class="string">'userLogin'</span>, reLogin: <span class="literal">false</span> &#125;</span>) =&gt;</span> &#123;</span><br><span class="line">  <span class="keyword">return</span> <span class="keyword">new</span> <span class="built_in">Promise</span>(<span class="function">(<span class="params">resolve, reject</span>) =&gt;</span> &#123;</span><br><span class="line">    wx.login(&#123;</span><br><span class="line">      success: <span class="function"><span class="params">res</span> =&gt;</span> &#123;</span><br><span class="line">        <span class="keyword">const</span> &#123; code &#125; = res <span class="comment">// 获取code</span></span><br><span class="line">        <span class="keyword">const</span> query = &#123; code, cmd, reLogin &#125;</span><br><span class="line">        <span class="comment">// 是否重新登录</span></span><br><span class="line">        <span class="keyword">if</span>(reLogin) &#123;</span><br><span class="line">          <span class="keyword">delete</span> query.reLogin <span class="comment">// 不带上重新登录的标志</span></span><br><span class="line">          <span class="comment">// new Fly()新实例</span></span><br><span class="line">          <span class="keyword">new</span> Fly().post(fly.config.baseURL + <span class="string">'/user_login'</span>, query).then(<span class="function"><span class="params">r</span> =&gt;</span> &#123;</span><br><span class="line">            <span class="keyword">const</span> &#123; user_id, token &#125; = r.data.result <span class="comment">// 最新token</span></span><br><span class="line">            wx.setStorageSync(<span class="string">'Token'</span>, token)</span><br><span class="line">            wx.setStorageSync(<span class="string">'UserId'</span>, user_id)</span><br><span class="line">            resolve(r)</span><br><span class="line">          &#125;)</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">          <span class="comment">// fly实例</span></span><br><span class="line">          fly.post(<span class="string">'/user_login'</span>, query).then(<span class="function"><span class="params">r</span> =&gt;</span> &#123;</span><br><span class="line">            <span class="keyword">const</span> &#123; user_id, token &#125; = r.result</span><br><span class="line">            wx.setStorageSync(<span class="string">'Token'</span>, token)</span><br><span class="line">            wx.setStorageSync(<span class="string">'UserId'</span>, user_id)</span><br><span class="line">            resolve(r)</span><br><span class="line">          &#125;)</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;,</span><br><span class="line">      fail: <span class="function"><span class="params">err</span> =&gt;</span> &#123; reject(err) &#125;,</span><br><span class="line">      complete: <span class="function"><span class="params">()</span> =&gt;</span> &#123;&#125;</span><br><span class="line">    &#125;)</span><br><span class="line">  &#125;)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>代码比较短，就是很常规的调用微信登录<code>wx.login</code>获取用户<code>code</code>值给给后端换取<code>token</code>，最后返回一个<code>promise</code>对象。</p>
<p><strong>注意：</strong>这里需要注意的是传入的参数为<code>reLogin:true</code>的情况</p>
<ol>
<li><p>如果为<code>true</code>则表示重新登录，即表示当前<code>fly</code>实例已被锁定，故无法使用<code>fly</code>实例发起登录请求，需要新创建一个<code>fly</code>实例去发起登录请求，所以有<code>new Fly()</code></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">新实例<span class="keyword">new</span> Fly()没有定义拦截器和基准路径，故需要将路径补全，但原来的基准路径直接使用即可</span><br><span class="line">即<span class="keyword">new</span> Fly().post(fly.config.baseURL + <span class="string">'/user_login'</span>, query)</span><br></pre></td></tr></table></figure>
</li>
</ol>
<ol start="2">
<li><p>如果为<code>false</code>则表示正常的小程序登录，直接使用原来的<code>fly</code>实例发起登录即可</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">此处我将wxLogin登录流程写在fly.js中，方便拦截器中token失效重新登录，</span><br><span class="line">然后将wxLogin函数暴露出去，在需要的地方跟其他api一样使用</span><br></pre></td></tr></table></figure>
<p>至此，可以尝试下在<code>token</code>失效的情况，都能重新登录之后重新发起请求，nice啊 ·(✪ω✪)·</p>
</li>
</ol>
<h3 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h3><p>我只是个搬砖工啊啊啊啊…</p>
<h3 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h3><p><strong>fly.js</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// fly.js</span></span><br><span class="line"><span class="keyword">var</span> Fly = <span class="built_in">require</span>(<span class="string">'flyio/dist/npm/wx'</span>)</span><br><span class="line"><span class="keyword">var</span> fly = <span class="keyword">new</span> Fly(); <span class="comment">// 创建fly实例</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 以下 cmd 不展示 loading</span></span><br><span class="line"><span class="keyword">const</span> hideLoadingArr = [<span class="string">'getConfig'</span>, <span class="string">'getPostList'</span>, <span class="string">'getBannerList'</span>, <span class="string">'userLogin'</span>, <span class="string">'formId'</span>, <span class="string">'hasNewDocMsgs'</span>]</span><br><span class="line"></span><br><span class="line"><span class="comment">// 请求拦截</span></span><br><span class="line">fly.interceptors.request.use(<span class="function">(<span class="params">config, promise</span>) =&gt;</span> &#123;</span><br><span class="line">  <span class="comment">// 不在列表中则展示loading</span></span><br><span class="line">  <span class="keyword">if</span>(hideLoadingArr.indexOf(config.body.cmd) === <span class="number">-1</span>) &#123;</span><br><span class="line">    wx.showLoading(&#123; <span class="attr">title</span>: <span class="string">'Loading...'</span> &#125;)</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="comment">// 状态栏转圈</span></span><br><span class="line">  wx.showNavigationBarLoading()</span><br><span class="line">  <span class="comment">// 给请求带上 token</span></span><br><span class="line">  config.body.token = wx.getStorageSync(<span class="string">'Token'</span>)</span><br><span class="line">  config.body.user_id = wx.getStorageSync(<span class="string">'UserId'</span>)</span><br><span class="line">  <span class="keyword">return</span> config</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line"><span class="comment">// 响应拦截</span></span><br><span class="line">fly.interceptors.response.use(<span class="function"><span class="keyword">function</span> (<span class="params">res</span>)</span>&#123;</span><br><span class="line">  <span class="comment">// 隐藏loading</span></span><br><span class="line">  wx.hideLoading()</span><br><span class="line">  <span class="comment">// 状态栏停止转圈</span></span><br><span class="line">  wx.hideNavigationBarLoading()</span><br><span class="line">  <span class="comment">// token过期 =&gt; 重新登录处理</span></span><br><span class="line">  <span class="keyword">if</span>(res.data.errcode === <span class="number">-1</span>) &#123;</span><br><span class="line">    <span class="keyword">this</span>.lock() <span class="comment">// 锁定响应拦截器，实际上并没有锁定后面的请求，还是会重复发起重新登录请求，不明所以</span></span><br><span class="line">    <span class="keyword">return</span> wxLogin(&#123;<span class="string">'reLogin'</span>: <span class="literal">true</span> &#125;).then(<span class="function"><span class="params">r</span> =&gt;</span> &#123;</span><br><span class="line">      <span class="keyword">this</span>.unlock() <span class="comment">// 解锁，因小程序中无finally，只能在此解锁</span></span><br><span class="line">      <span class="keyword">return</span> fly.request(res.request) <span class="comment">// 重新请求res.request.url</span></span><br><span class="line">    &#125;).catch(<span class="function"><span class="params">err</span> =&gt;</span> <span class="keyword">this</span>.unlock())</span><br><span class="line">  &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> res.data</span><br><span class="line">  &#125;</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line"><span class="comment">// 导出默认的fly</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> fly</span><br><span class="line"></span><br><span class="line"><span class="comment">// 因为要调用微信的wx.login接口获取code，故将登录接口放置在此，方便token失效时重新登录使用</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">const</span> wxLogin = <span class="function">(<span class="params">&#123; cmd = <span class="string">'userLogin'</span>, reLogin = <span class="literal">false</span> &#125; = &#123; cmd: <span class="string">'userLogin'</span>, reLogin: <span class="literal">false</span> &#125;</span>) =&gt;</span> &#123;</span><br><span class="line">  <span class="keyword">return</span> <span class="keyword">new</span> <span class="built_in">Promise</span>(<span class="function">(<span class="params">resolve, reject</span>) =&gt;</span> &#123;</span><br><span class="line">    wx.login(&#123;</span><br><span class="line">      success: <span class="function"><span class="params">res</span> =&gt;</span> &#123;</span><br><span class="line">        <span class="keyword">const</span> &#123; code &#125; = res <span class="comment">// 获取code</span></span><br><span class="line">        <span class="keyword">const</span> query = &#123; code, cmd, reLogin &#125;</span><br><span class="line">        <span class="comment">// 是否重新登录</span></span><br><span class="line">        <span class="keyword">if</span>(reLogin) &#123;</span><br><span class="line">          <span class="keyword">delete</span> query.reLogin <span class="comment">// 不带上重新登录的标志</span></span><br><span class="line">          <span class="keyword">new</span> Fly().post(fly.config.baseURL + <span class="string">'/user_login'</span>, query).then(<span class="function"><span class="params">r</span> =&gt;</span> &#123;</span><br><span class="line">            <span class="keyword">const</span> &#123; user_id, token &#125; = r.data.result <span class="comment">// 新的fly实例多包装了一层data</span></span><br><span class="line">            wx.setStorageSync(<span class="string">'Token'</span>, token)</span><br><span class="line">            wx.setStorageSync(<span class="string">'UserId'</span>, user_id)</span><br><span class="line">            resolve(r)</span><br><span class="line">          &#125;)</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">          fly.post(<span class="string">'/user_login'</span>, query).then(<span class="function"><span class="params">r</span> =&gt;</span> &#123;</span><br><span class="line">            <span class="keyword">const</span> &#123; user_id, token &#125; = r.result</span><br><span class="line">            wx.setStorageSync(<span class="string">'Token'</span>, token)</span><br><span class="line">            wx.setStorageSync(<span class="string">'UserId'</span>, user_id)</span><br><span class="line">            resolve(r)</span><br><span class="line">          &#125;)</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;,</span><br><span class="line">      fail: <span class="function"><span class="params">err</span> =&gt;</span> &#123; reject(err) &#125;,</span><br><span class="line">      complete: <span class="function"><span class="params">()</span> =&gt;</span> &#123;&#125;</span><br><span class="line">    &#125;)</span><br><span class="line">  &#125;)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 配置请求基准路径  测试环境</span></span><br><span class="line">fly.config.baseURL = <span class="string">"https://dev2/api"</span></span><br><span class="line"><span class="comment">// 正式环境</span></span><br><span class="line"><span class="comment">// fly.config.baseURL = "https://prod/api"</span></span><br></pre></td></tr></table></figure>

        </div>

        <blockquote class="post-copyright">
    
    <div class="content">
        
<span class="post-time">
    最后更新时间：<time datetime="2019-09-17T05:44:37.921Z" itemprop="dateUpdated">2019-09-17 13:44:37</time>
</span><br>


        
        关于学习类文章网上已经有非常多，而此处文章都是我在学习过程中整理摘录的笔记，参考文章可以点击文末的参考链接进行查阅
        
    </div>
    
    <footer>
        <a href="https://lafen.gitee.io">
            <img src="/img/avatar.jpg" alt="lafen">
            lafen
        </a>
    </footer>
</blockquote>

        
<div class="page-reward">
    <a id="rewardBtn" href="javascript:;" class="page-reward-btn waves-effect waves-circle waves-light">赏</a>
</div>



        <div class="post-footer">
            
	<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/mpvue/">mpvue</a></li></ul>


            
<div class="page-share-wrap">
    

<div class="page-share" id="pageShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=https://lafen.gitee.io/2019/08/30/mpvue-使用flyio发起request请求/mpvue-使用flyio发起request请求/&title=《mpvue-使用flyio发起request请求》 — lafen&pic=https://lafen.gitee.io/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=https://lafen.gitee.io/2019/08/30/mpvue-使用flyio发起request请求/mpvue-使用flyio发起request请求/&title=《mpvue-使用flyio发起request请求》 — lafen&source=lafen's personal blog" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https://lafen.gitee.io/2019/08/30/mpvue-使用flyio发起request请求/mpvue-使用flyio发起request请求/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《mpvue-使用flyio发起request请求》 — lafen&url=https://lafen.gitee.io/2019/08/30/mpvue-使用flyio发起request请求/mpvue-使用flyio发起request请求/&via=https://lafen.gitee.io" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=https://lafen.gitee.io/2019/08/30/mpvue-使用flyio发起request请求/mpvue-使用flyio发起request请求/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>



    <a href="javascript:;" id="shareFab" class="page-share-fab waves-effect waves-circle">
        <i class="icon icon-share-alt icon-lg"></i>
    </a>
</div>



        </div>
    </div>

    
<nav class="post-nav flex-row flex-justify-between">
  
    <div class="waves-block waves-effect prev">
      <a href="/2019/09/08/mpvue-趟坑--视图更新问题/mpvue-趟坑--视图更新问题/" id="post-prev" class="post-nav-link">
        <div class="tips"><i class="icon icon-angle-left icon-lg icon-pr"></i> Prev</div>
        <h4 class="title">mpvue-趟坑--视图更新问题</h4>
      </a>
    </div>
  

  
    <div class="waves-block waves-effect next">
      <a href="/2019/08/18/mpvue-自定义导航栏/mpvue-自定义导航栏/" id="post-next" class="post-nav-link">
        <div class="tips">Next <i class="icon icon-angle-right icon-lg icon-pl"></i></div>
        <h4 class="title">mpvue-自定义导航栏</h4>
      </a>
    </div>
  
</nav>



    




















</article>

<div id="reward" class="page-modal reward-lay">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <h3 class="reward-title">
        <i class="icon icon-quote-left"></i>
        打笔巨款？~
        <i class="icon icon-quote-right"></i>
    </h3>
    <div class="reward-content">
        
        <div class="reward-code">
            <img id="rewardCode" src="/img/wechat.jpg" alt="打赏二维码">
        </div>
        
        <label class="reward-toggle">
            <input id="rewardToggle" type="checkbox" class="reward-toggle-check" data-wechat="/img/wechat.jpg" data-alipay="/img/alipay.jpg">
            <div class="reward-toggle-ctrol">
                <span class="reward-toggle-item wechat">微信</span>
                <span class="reward-toggle-label"></span>
                <span class="reward-toggle-item alipay">支付宝</span>
            </div>
        </label>
        
    </div>
</div>



</div>

        <footer class="footer">
    <div class="top">
        
<p>
    <span id="busuanzi_container_site_uv" style="display:none">
        站点总访客数：<span id="busuanzi_value_site_uv"></span>
    </span>
    <span id="busuanzi_container_site_pv" style="display:none">
        站点总访问量：<span id="busuanzi_value_site_pv"></span>
    </span>
</p>


        <p>
            
                <span><a href="/atom.xml" target="_blank" class="rss" title="rss"><i class="icon icon-lg icon-rss"></i></a></span>
            
            <span>博客内容遵循 <a rel="license" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">知识共享 署名 - 非商业性 - 相同方式共享 4.0 国际协议</a></span>
        </p>
    </div>
    <div class="bottom">
        <p><span>lafen &copy; 2019 - 2020</span>
            <span>
                
                Power by <a href="http://hexo.io/" target="_blank">Hexo</a> Theme <a href="https://github.com/yscoder/hexo-theme-indigo" target="_blank">indigo</a>
            </span>
        </p>
    </div>
</footer>

    </main>
    <div class="mask" id="mask"></div>
<a href="javascript:;" id="gotop" class="waves-effect waves-circle waves-light"><span class="icon icon-lg icon-chevron-up"></span></a>



<div class="global-share" id="globalShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=https://lafen.gitee.io/2019/08/30/mpvue-使用flyio发起request请求/mpvue-使用flyio发起request请求/&title=《mpvue-使用flyio发起request请求》 — lafen&pic=https://lafen.gitee.io/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=https://lafen.gitee.io/2019/08/30/mpvue-使用flyio发起request请求/mpvue-使用flyio发起request请求/&title=《mpvue-使用flyio发起request请求》 — lafen&source=lafen's personal blog" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https://lafen.gitee.io/2019/08/30/mpvue-使用flyio发起request请求/mpvue-使用flyio发起request请求/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《mpvue-使用flyio发起request请求》 — lafen&url=https://lafen.gitee.io/2019/08/30/mpvue-使用flyio发起request请求/mpvue-使用flyio发起request请求/&via=https://lafen.gitee.io" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=https://lafen.gitee.io/2019/08/30/mpvue-使用flyio发起request请求/mpvue-使用flyio发起request请求/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>


<div class="page-modal wx-share" id="wxShare">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <p>扫一扫，分享到微信</p>
    <img src="" alt="微信分享二维码">
</div>




    <script src="//cdn.bootcss.com/node-waves/0.7.4/waves.min.js"></script>
<script>
var BLOG = { ROOT: '/', SHARE: true, REWARD: true };


</script>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/main.min.js"></script>


<div class="search-panel" id="search-panel">
    <ul class="search-result" id="search-result"></ul>
</div>
<template id="search-tpl">
<li class="item">
    <a href="{path}" class="waves-block waves-effect">
        <div class="title ellipsis" title="{title}">{title}</div>
        <div class="flex-row flex-middle">
            <div class="tags ellipsis">
                {tags}
            </div>
            <time class="flex-col time">{date}</time>
        </div>
    </a>
</li>
</template>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/search.min.js" async></script>






<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>



<script>
(function() {
    var OriginTitile = document.title, titleTime;
    document.addEventListener('visibilitychange', function() {
        if (document.hidden) {
            document.title = '死鬼去哪里了！';
            clearTimeout(titleTime);
        } else {
            document.title = '(つェ⊂)咦!又好了!';
            titleTime = setTimeout(function() {
                document.title = OriginTitile;
            },2000);
        }
    });
})();
</script>



<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"scale":1,"jsonPath":"/live2dw/assets/shizuku.model.json"},"display":{"positon":"right","width":150,"height":300},"mobile":{"show":true,"scale":0.8},"react":{"opacity":0.8,"opacityDefault":0.8,"opacityOnHover":0.6},"log":false});</script></body>
</html>
